#ifndef CLIB_CYCLE_H
#define CLIB_CYCLE_H

#pragma once


#ifdef __cplusplus
extern "C" {
#endif

#include "clib_core.h"
#include "clib_config.h"
#include "clib_spinlock.h"
#include "clib_handle.h"
#include "clib_port_conf.h"

#define CLIB_MOD_MAX    1024

struct clib_cycle_s 
{
    clib_module_t            *mods[CLIB_MOD_MAX];
    i32_t                     mods_cnt;
    clib_module_t            *active_mods[CLIB_MOD_MAX];
    i32_t                     active_mods_cnt;
    clib_module_t            *unload_mods[CLIB_MOD_MAX];
    i32_t                     unload_mods_cnt;
    clib_lcore_cycle_t        lcore_cycle[CLIB_MOD_MAX];
    i32_t                     lcore_cnt;
    void                     *conf[CLIB_MOD_MAX];
    clib_port_conf_t          port_conf;
    clib_config_t            *conf;
    clib_netif_t              netif[32];
    i32_t                     socket_id;
    i32_t                     status;
    i32_t                     is_rpc;
    i32_t                     is_db;
    i32_t                     rpc_sfd;
    i32_t                     rpc_efd;
};

struct clib_lcore_cycle_s
{
    i16_t                   type;
    i16_t                   index;
    i16_t                   lcore_id;
    i32_t                   socket_id;
    i32_t                   status;
    clib_spinlock_t         lock;
    void                   *conf[CLIB_MOD_MAX];
    clib_cycle_t           *cycle;
    clib_handle_t          *handle[2];
    i32_t                   handle_cnt[2];
    i32_t                   handle_idx;
};


/**
 * 运行环境初始化.
 *
 * @param core
 *   配置文件[core]输入参数
 * @return
 *  0 成功
 * -1 失败
 */
i32_t clib_load_cycle(clib_core_conf_t* core);

#ifdef __cplusplus
}
#endif

#endif